#!/bin/bash
R="\\033[31m"
E="\\033[0m"
B="\\033[34m"
P="\\033[35m"
INSTALL_LOG='/tmp/install.log'

#升级所需要的库文件，编译工具…
yum -y install gcc automake autoconf libtool make gcc-c++ libxml2 libxml2-devel libjpeg-devel libpng-devel libfreetype6-devel libt1-devel libmcrypt-devel libXpm-devel curl-devel ncurses-devel glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel mhash-devel

sleep 2
cd /usr/local/src

#nginx依赖包

if [ -s openssl-0.9.8c.tar.gz ]
then
	echo -e "$B openssl-0.9.8c.tar.gz....................found $E"
else
	echo -e "$R openssl-0.9.8c.tar.gz.......not found,download now $E"
	wget http://www.openssl.org/source/openssl-0.9.8c.tar.gz
fi


if [ -s pcre-8.36.tar.gz ]
then
	echo -e "$B pcre-8.36.tar.gz....................found $E"
else 
	echo -e "$R pcre-8.36.tar.gz.......not found,download now $E"
	wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz
fi


if [ -s zlib-1.2.8.tar.gz ]
then
	echo -e "$B zlib-1.2.8.tar.gz....................found $E"
else
	echo -e "$R zlib-1.2.8.tar.gz.......not found,download now $E"
	wget http://zlib.net/zlib-1.2.8.tar.gz
fi


#mysql依赖包
if [ -s mysql-5.6.21.tar.gz ]
then
	echo -e "$B mysql-5.6.21.tar.gz....................found $E"
else
	echo -e "$R mysql-5.6.21.tar.gz.......not found,download now $E"
	wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
fi

if [ -s ncurses-5.9.tar.gz ]
then
        echo -e "$B ncurses-5.9.tar.gz....................found $E"
else
        echo -e "$R ncurses-5.9.tar.gz.......not found,download now $E"
	wget ftp://mirrors.ustc.edu.cn/gnu/ncurses/ncurses-5.9.tar.gz
fi

if [ -s cmake-2.8.7.tar.gz ]
then
    echo -e "$B cmake-2.8.7.tar.gz....................found $E"
else
    echo -e "$R cmake-2.8.7.tar.gz.......not found,download now $E"
	wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
fi

if [ -s bison-3.0.tar.gz ]
then
    echo -e "$B bison-3.0.tar.gz....................found $E"
else
    echo -e "$R bison-3.0.tar.gz.......not found,download now $E"
	wget http://ftp.gnu.org/gnu/bison/bison-3.0.tar.gz
fi



#php依赖包
if [ -s php-5.6.3.tar.gz ]
then
	echo -e "$B php-5.6.3.tar.gz....................found $E"
else
	echo -e "$R php-5.6.3.tar.gz.......not found,download now $E"
	wget http://cn2.php.net/distributions/php-5.6.3.tar.gz
fi

if [ -s libpng-1.6.15.tar.gz ]
then
    echo -e "$B libpng-1.6.15.tar.gz....................found $E"
else
    echo -e "$R libpng-1.6.15.tar.gz.......not found,download now $E"
	wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.15.tar.gz
fi

if [ -s freetype-2.5.0.1.tar.gz ]
then
    echo -e "$B freetype-2.5.0.1.tar.gz....................found $E"
else
    echo -e "$R freetype-2.5.0.1.tar.gz.......not found,download now $E"
	wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.1.tar.gz
fi

if [ -s libxml2-2.9.0.tar.gz ]
then
    echo -e "$B libxml2-2.9.0.tar.gz....................found $E"
else
    echo -e "$R libxml2-2.9.0.tar.gz.......not found,download now $E"
	wget ftp://ftp.mirrorservice.org/sites/distfiles.macports.org/libxml2/libxml2-2.9.0.tar.gz
fi

if [ -f gd-2.1.0-src-11.11.tar.gz ]
then
    echo -e "$B gd-2.1.0-src-11.11.tar.gz. ...................found $E"
else
    echo -e "$R gd-2.1.0-src-11.11.tar.gz .......not found,download now $E"
	wget ftp://ftp.connect.org.uk/hpux/Development/Libraries/gd-2.1.0/gd-2.1.0-src-11.11.tar.gz
fi

if [ -s bzip2-1.0.6.tar.gz ]
then
        echo -e "$B bzip2-1.0.6.tar.gz....................found $E"
else
        echo -e "$R bzip2-1.0.6.tar.gz.......not found,download now $E"
		wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
fi

#php常用扩展
if [ -s libiconv-1.13.tar.gz ]
then
    echo -e "$B libiconv-1.13.tar.gz ................................... found $E"
else
    echo -e "$R libiconv-1.13.tar.gz ...............not found ,download now....$E"
    wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.tar.gz
fi

if [ -s jpegsrc.v6b.tar.gz ]
then
	echo -e "$B jpegsrc.v6b.tar.gz ................................... found $E"
else
	echo -e "$R jpegsrc.v6b.tar.gz ...............not found ,download now....$E"
	wget ftp://ftp.tw.freebsd.org/pub/branches/-current/ports/distfiles/jpegsrc.v6b.tar.gz
fi


if [ -s libmcrypt-2.5.8.tar.gz ]
then
    echo -e "$B libmcrypt-2.5.8.tar.gz ..................................found $E"
else
    echo -e " $R libmcrypt-2.5.8.tar.gz ...........not found ,download new.... $E"
    wget http://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz
fi

if [ -s mcrypt-2.6.8.tar.gz ]
then
    echo -e "$B mcrypt-2.6.8.tar.gz .....................................found $E"
else
    echo -e "$R mcrypt-2.6.8.tar.gz ................not found ,download new....$E"
    wget http://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
fi

if [ -s mhash-0.9.9.9.tar.gz ]
then
    echo -e "$B mhash-0.9.9.9.tar.gz ....................................found $E"
else
    echo -e "$R mhash-0.9.9.9.tar.gz ...............not found ,download new....$E "
    wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
fi

if [ -s nginx-1.4.3.tar.gz ]
then
    echo -e "$B nginx-1.4.3.tar.gz ....................................found $E"
else
    echo -e "$R nginx-1.4.3.tar.gz ...............not found ,download new....$E "
    wget ftp://ftp.tw.freebsd.org/pub/branches/-current/ports/distfiles/nginx-1.4.3.tar.gz
fi



#安装mysql5.5.20
if [ $(cat $INSTALL_LOG | grep 'ncurses-5.9' | wc -l) == 0 ]
then
	tar zxvf ncurses-5.9.tar.gz
	cd ncurses-5.9
	./configure
	make && make install
	if [ $? != 0 ];then
		echo -e "$R install ncurses-5.9 error $E"
		exit 1
	fi
	cd ../
	echo -e "\033[32m=========ncurses-5.9 is ok========\033[0m"
	echo "ncurses-5.9 is ok" >> $INSTALL_LOG
else
	echo -e "\033[32m=========ncurses-5.9 already installed========\033[0m"
fi
sleep 2

if [ $(cat $INSTALL_LOG | grep 'cmake-2.8.7' | wc -l) == 0 ]
then
	tar zxvf cmake-2.8.7.tar.gz
	cd cmake-2.8.7
	./configure
	make && make install
	if [ $? != 0 ];then
		echo -e "$R install make error $E"
		exit 1
	fi
	cd ../
	echo -e "\033[32m=========cmake-2.8.7 is ok========\033[0m"
	echo "cmake-2.8.7 is ok" >> $INSTALL_LOG
else
	echo -e "\033[32m=========cmake-2.8.7 already installed========\033[0m"
fi
sleep 2

if [ $(cat $INSTALL_LOG | grep 'bison-3.0' | wc -l) == 0 ]
then
	tar zxvf bison-3.0.tar.gz
	cd bison-3.0
	./configure
	make && make install
	if [ $? != 0 ];then
		echo -e "$R install bison-3.0 error $E"
		exit 1
	fi
	cd ../
	echo -e "\033[32m=========bison-3.0 is ok========\033[0m"
	echo "bison-3.0 is ok" >> $INSTALL_LOG
else
	echo -e "\033[32m=========bison-3.0 already installed========\033[0m"
fi
sleep 2

if [ $(cat $INSTALL_LOG | grep 'mysql-5.6' | wc -l) == 0 ]
then
	groupadd mysql
	useradd mysql -g mysql
	tar zxvf mysql-5.6.21.tar.gz
	cd mysql-5.6.21
	cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
		  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
		  -DEXTRA_CHARSETS=all \
		  -DDEFAULT_CHARSET=utf8 \
		  -DDEFAULT_COLLATION=utf8_general_ci \
		  -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
		  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
		  -DWITH_READLINE=1 \
		  -DENABLED_LOCAL_INFILE=1 \
		  -DMYSQL_DATADIR=/data/mysql/ \
		  -DMYSQL_USER=mysql \
		  -DMYSQL_TCP_PORT=3306
	make && make install
	if [ $? == 0 ]
	then
		echo -e "\033[32m=========mysqld is ok========\033[0m"
		echo "mysql-5.6 is ok" >> $INSTALL_LOG
		
		mkdir -p /data/mysql
		chown mysql.mysql -R /data/mysql
		mv /etc/my.cnf /etc/my.cnf-old 
		cp support-files/my-default.cnf /etc/my.cnf
		chmod 755 scripts/mysql_install_db
		scripts/mysql_install_db  --user=mysql  --basedir=/usr/local/mysql --datadir=/data/mysql/
		cp support-files/mysql.server /etc/init.d/mysqld
		chmod 755 /etc/init.d/mysqld
		chkconfig mysqld on
		service mysqld start

		### install mysql admin password for 123456
		/usr/local/mysql/bin/mysqladmin -u root password '123456'
	fi
		cd ../
fi


#安装php
echo -e "\033[32m=========libpng start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'libpng-1.6.15' | wc -l) == 0 ]
then
	tar zxvf libpng-1.6.15.tar.gz
	cd libpng-1.6.15
	./configure
	make && make install
	if [ $? != 0 ];then
		echo -e "$R install libpng-1.6.15 error $E"
		exit 1
	fi
	echo -e "\033[32m=========libpng-1.6.15 is ok========\033[0m"
	echo "libpng-1.6.15 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========libpng-1.6.15 already installed========\033[0m"
fi
sleep 2

#安装freetype
echo -e "\033[32m=========freetype start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'freetype-2.5' | wc -l) == 0 ]
then
	tar zxvf freetype-2.5.0.1.tar.gz
	cd freetype-2.5.0.1
	./configure --prefix=/usr/local/freetype
	make && make install
	if [ $? != 0 ];then
		echo -e "$R install freetype-2.5.0.1 error $E"
		exit 1
	fi
	echo -e "\033[32m=========freetype-2.5.0.1 is ok========\033[0m"
	echo "freetype-2.5.0.1 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========freetype-2.5.0.1 already install========\033[0m"
fi
sleep 2

#安装jpeg
echo -e "\033[32m=========jpeg start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'jpeg' | wc -l) == 0 ]
then
	mkdir /usr/local/jpeg
	mkdir -p /usr/local/jpeg/include
	mkdir -p /usr/local/jpeg/lib
	mkdir -p /usr/local/jpeg/bin
	mkdir -p /usr/local/jpeg/man
	mkdir -p /usr/local/jpeg/man/man1
	tar zxvf jpegsrc.v6b.tar.gz
	cd jpeg-6b
	./configure --prefix=/usr/local/jpeg
	make && make install
	if [ $? != 0 ];then
	    echo -e "$R install jpeg error $E"
	    exit 1
	fi
	echo -e "\033[32m=========jpeg is ok========\033[0m"
	echo -e "jpeg is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========jpeg already install========\033[0m"
fi
sleep 2

#安装zlib
echo -e "\033[32m=========zlib-1.2.8 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'zlib-1.2.8' | wc -l) == 0 ]
then
	tar zxvf zlib-1.2.8.tar.gz
	cd zlib-1.2.8
	./configure
	make && make install
	if [ $? != 0 ];then
	    echo -e "$R install zlib-1.2.8 error $E"
	    exit 1
	fi
	echo -e "\033[32m=========zlib-1.2.8 is ok========\033[0m"
	echo -e "zlib-1.2.8 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========zlib-1.2.8 already install========\033[0m"
fi
sleep 2

#安装gd
echo -e "\033[32m=========gd-2.1.0-src-11.11 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'gd-2.1.0' | wc -l) == 0 ]
then
	tar zxvf gd-2.1.0-src-11.11.tar.gz
	cd gd-2.1.0/
	./configure --prefix=/usr/local/gd \
	--with-png \
	--with-jpeg=/usr/local/jpeg \
	--with-freetype=/usr/local/freetype
	make && make install
	if [ $? != 0 ];then
	    echo "install gd-2.1.0 error"
	    exit 1
	fi
	echo -e "\033[32m=========gd-2.1.0 is ok========\033[0m"
	echo -e "gd-2.1.0 is ok" >> $INSTALL_LOG
	cd ../../
else
	echo -e "\033[32m=========gd-2.1.0 already install========\033[0m"
fi
sleep 2

#安装bzip
echo -e "\033[32m=========bzip2-1.0.6 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'bzip2-1.0.6' | wc -l) == 0 ]
then
	tar zxvf bzip2-1.0.6.tar.gz
	cd bzip2-1.0.6
	make && make install
	if [ $? != 0 ];then
	    echo "$R install bzip2-1.0.6 error $E"
	    exit 1
	fi
	echo -e "\033[32m=========bzip2-1.0.6 is ok========\033[0m"
	echo -e "bzip2-1.0.6 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========bzip2-1.0.6 already install========\033[0m"
fi
sleep 2

###libiconv
echo -e "\033[32m=========libiconv-1.13 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'libiconv-1.13' | wc -l) == 0 ]
then
	tar zxvf libiconv-1.13.tar.gz
	cd libiconv-1.13/
	./configure --prefix=/usr/local
	make && make install
	if [ $? != 0 ];then
	    echo "$R install libiconv-1.13 error $E"
	    exit 1
	fi
	echo -e "\033[32m=========libiconv-1.13 is ok========\033[0m"
	echo -e "libiconv-1.13 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========libiconv-1.13 already install========\033[0m"
fi
sleep 2

###libmcrypt
echo -e "\033[32m=========libmcrypt-2.5.8 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'libmcrypt-2.5.8' | wc -l) == 0 ]
then
	tar zxvf libmcrypt-2.5.8.tar.gz
	cd libmcrypt-2.5.8/
	./configure
	make && make install
	if [ $? != 0 ];then
	    echo "$R install libmcrypt-2.5.8 error $E"
	    exit 1
	fi
	/sbin/ldconfig
	cd libltdl/
	./configure --enable-ltdl-install
	make && make install
	echo -e "\033[32m=========libmcrypt-2.5.8 is ok========\033[0m"
	echo -e "libmcrypt-2.5.8 is ok" >> $INSTALL_LOG
	cd ../../
else
	echo -e "\033[32m=========libmcrypt-2.5.8 already install========\033[0m"
fi

###mhash
echo -e "\033[32m=========mhash-0.9.9.9 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'mhash-0.9.9.9' | wc -l) == 0 ]
then
	tar zxvf mhash-0.9.9.9.tar.gz
	cd mhash-0.9.9.9/
	./configure
	make && make install
	if [ $? != 0 ];then
	    echo "$R install mhash-0.9.9.9 error $E"
	    exit 1
	fi
	echo -e "\033[32m=========mhash-0.9.9.9 is ok========\033[0m"
	echo -e "mhash-0.9.9.9 is ok" >> $INSTALL_LOG
	cd ../
	ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
	ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
	ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
	ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
	ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
	ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
	ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
	ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
	ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
	ln -s /usr/lib64/libldap* /usr/lib/
else
	echo -e "\033[32m=========mhash-0.9.9.9 already install========\033[0m"
fi

###mcrypt
echo -e "\033[32m=========mcrypt-2.6.8 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'mcrypt-2.6.8' | wc -l) == 0 ]
then
	tar zxvf mcrypt-2.6.8.tar.gz
	cd mcrypt-2.6.8/
	/sbin/ldconfig
	./configure
	make && make install
	if [ $? != 0 ];then
	    echo "$R install mcrypt-2.6.8 error $E"
	    exit 1
	fi
	echo -e "\033[32m=========mcrypt-2.6.8 is ok========\033[0m"
	echo -e "mcrypt-2.6.8 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========mcrypt-2.6.8 already install========\033[0m"
fi

#开始安装php
#动态链接库加载出错:cannot restore segment prot after reloc: Permission denied

#解决：
#这是因为SELINUX的问题，需要关闭SELINX，执行：/usr/sbin/setenforce 0 
/usr/sbin/setenforce 0 
echo -e "\033[32m=========php-5.6.3 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'php-5.6.3' | wc -l) == 0 ]
then
	mkdir /usr/local/php
	tar zxvf php-5.6.3.tar.gz
	cd php-5.6.3
	./configure --prefix=/usr/local/php \
	--with-config-file-path=/usr/local/php/etc \
	--with-curl \
	--with-gd=/usr/local/gd \
	--with-jpeg-dir=/usr/local/jpeg \
	--with-iconv-dir=/usr/local \
	--with-png-dir \
	--with-zlib \
	--with-libxml-dir=/usr/local/lib \
	--with-xpm-dir \
	--with-freetype-dir=/usr/local/freetype \
	--with-mcrypt \
	--with-mhash \
	--with-mysql=/usr/local/mysql \
	--with-mysqli=/usr/local/mysql/bin/mysql_config \
	--with-openssl \
	--with-xmlrpc \
	--enable-soap \
	--with-bz2 \
	--without-pear \
	--enable-fpm \
	--enable-wddx \
	--enable-zip \
	--enable-safe-mode \
	--enable-bcmath \
	--enable-calendar \
	--enable-fastcgi \
	--enable-ftp \
	--enable-mbstring \
	--enable-sysvshm

	if [ $? != 0 ];then
		echo "$R install php-5.6.3 error $E"
		exit 1
	fi

	sleep 1
	ln -s /usr/local/mysql/lib/libmysql*  /usr/lib64/
	make ZEND_EXTRA_LIBS='-liconv'
	make install
	cp -f php.ini-production /usr/local/php/etc/php.ini
	ln -s /usr/local/php/etc/php.ini /usr/local/php/php.ini
	cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf
	cd ../

	/usr/sbin/groupadd www   
    /usr/sbin/useradd -g www www  

    mv /usr/local/php/etc/php-fpm.conf /mnt/php-fpm.conf
	cd /mnt/
	sed -e '
	s#pm.max_children = 5#pm.max_children = 64#
	s#pm.start_servers = 2#pm.start_servers = 20#
	s#pm.min_spare_servers = 1#pm.min_spare_servers = 5#
	s#pm.max_spare_servers = 3#pm.max_spare_servers = 35#
	s#;pm.max_requests = 500#pm.max_requests = 1024#
	s#user = nobody#user = www#
	s#group = nobody#group = www#' /mnt/php-fpm.conf >/mnt/php-fpm.conf.bak

	rm -rf /usr/local/php/etc/php-fpm.conf
    mv /mnt/php-fpm.conf.bak /usr/local/php/etc/php-fpm.conf
    #进行开机设置
	echo "export PATH=\$PATH:/usr/local/php/sbin/" >>/etc/profile
	echo "export PATH=\$PATH:/usr/local/php/bin/" >>/etc/profile
	. /etc/profile
	echo -e "\033[32m=========php-5.6.3 is ok========\033[0m"
	echo -e "php-5.6.3 is ok" >> $INSTALL_LOG
	cd /usr/local/src/ 

else
	echo -e "\033[32m=========php-5.6.3 already install========\033[0m"
fi

#安装nginx

echo -e "\033[32m=========openssl-0.9.8c start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'openssl-0.9.8c' | wc -l) == 0 ]
then
	tar zxvf openssl-0.9.8c.tar.gz
	cd openssl-0.9.8c
	./config
	make && make install

	if [ $? != 0 ];then 
	  echo "install openssl-0.9.8c error" 
	  exit 1
	fi
	echo -e "\033[32m=========openssl-0.9.8c is ok========\033[0m"
	echo -e "openssl-0.9.8c is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========openssl-0.9.8c already install========\033[0m"
fi

#安装pcre-8.36
#ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
echo -e "\033[32m=========pcre-8.36 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'pcre-8.36' | wc -l) == 0 ]
then
	tar zxvf pcre-8.36.tar.gz
	cd pcre-8.36
	./configure --prefix=/usr/local/pcre-8.36
	make && make install
	if [ $? != 0 ];then
	  echo "install pcre-8.36 error"
	  exit 1
	fi
	echo -e "\033[32m=========pcre-8.36 is ok========\033[0m"
	echo -e "pcre-8.36 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========pcre-8.36 already install========\033[0m"
fi
sleep 2

#nginx
echo -e "\033[32m=========nginx-1.4.3 start install.....========\033[0m"
if [ $(cat $INSTALL_LOG | grep 'nginx-1.4.3' | wc -l) == 0 ]
then
	tar zxvf nginx-1.4.3.tar.gz
	cd nginx-1.4.3/
	./configure --user=www \
	--group=www \
	--prefix=/usr/local/nginx \
	--sbin-path=/usr/local/nginx/sbin/nginx \
	--conf-path=/usr/local/nginx/conf/nginx.conf \
	--with-http_stub_status_module \
	--with-http_ssl_module \
	--with-pcre=/usr/local/src/pcre-8.36 \
	--with-zlib=../zlib-1.2.8 \
	--with-openssl=../openssl-0.9.8c \
	--lock-path=/var/run/nginx.lock \
	--pid-path=/var/run/nginx.pid 

	make && make install
	echo -e "\033[32m=========nginx-1.4.3 is ok========\033[0m"
	echo -e "nginx-1.4.3 is ok" >> $INSTALL_LOG
	cd ../
else
	echo -e "\033[32m=========nginx-1.4.3 already install========\033[0m"
fi
sleep 2

#配置文件
cat >/usr/local/nginx/conf/nginx.conf<<EOF
user  www www;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    use epoll;
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status $body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        charset koi8-r;

        access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

     
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php\$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

}
EOF

#接着检查了服务器端的80端口是否可以访问的到：telnet 192.168.131.130 80， 结果访问不到，原来果真防火墙的问题。
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart

###设置开机启动
echo "/usr/local/php/sbin/php-fpm" >> /etc/rc.local
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
echo "/etc/init.d/mysqld restart" >> /etc/rc.local

#启动 server
/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx
/etc/init.d/mysqld restart
